{layout name="public/layout" /}
{include file='yxnavbar'}
<style>
    .table td span {
        display: inline-block;
        margin-top: 4px;
    }

    .table td input {
        margin-bottom: 0;
    }
</style>
<div>
    <ul class="nav nav-tabs">
        <li {if $index} class="active" {/if}>
            <a href="{php echo createWebUrl('clottery',array('op' => 'index','themeid'=>$themeid));}">新增奖品</a>
        </li>
        <li {if $list }class="active" {/if}>
            <a href="{php echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid));}">奖品列表</a>
        </li>
        <li {if $recode}class="active" {/if}>
            <a href="{php echo createWebUrl('clottery',array('op' => 'recode','themeid'=>$themeid));}">中奖名单</a>
        </li>
    </ul>
</div>
{if $index}
<div>
    <form class="form-horizontal form"
        action="{php echo createWebUrl('clottery',array('op' => 'add','themeid'=>$themeid));}" id="form1"
        method="post" enctype="multipart/form-data">
        <div class="main">
            <div class="tab-content">
                <div class="tab-pane active" id="basic">
                    <div class="panel panel-default" role="tabpanel">
                        <div class="panel-heading">抽奖信息</div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label class="col-sm-2 col-xs-12 control-label">奖品标题</label>
                                <div class="col-sm-8 col-xs-12">
                                    <input type="text" class="form-control" placeholder="" name="name"
                                        value="{$lottery['name']}">
                                    <span class="help-block">奖品标题建议8字以内</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-xs-12 control-label">奖品图标</label>
                                <div class="col-sm-8 col-xs-12">
                                    {php echo view_form_field_image('icon',$lottery['icon']);}
                                    <span class="help-block">奖品图标，建议100*100</span>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <input name="submit" id="btnConfirm" type="submit" value="提交" class="btn btn-primary col-lg-2"
                    style="float: right;">
                <input type="hidden" name="__token__" value="{$Request.token}" />
            </div>
        </div>
    </form>
    {/if}
    {if $list}
    <div class="main">
        <div class="tab-content">
            <div class="tab-pane active" id="basic">
                <div class="panel panel-default" role="tabpanel">
                    <div class="panel-heading">奖品列表</div>
                    <table class="table bootstrap-table table-hover site-list">
                        <tr>
                            <th colspan="2" class="text-left">
                                奖品图标
                            </th>
                            <th class="text-left" width="160px">
                                奖品名称
                            </th>
                            <th class="text-left" width="160px">
                                中奖名单
                            </th>
                            <th class="text-left" width="160px">
                                操作
                            </th>
                        </tr>
                        {loop $list $item}
                        <tr>
                            <td colspan="2"><img style="width: 100px;height: 100px;" src="{php echo tomedia($item['icon']);}" /></td>
                            <td class="text-left">{$item['name']}</td>
                            <td class="text-left">
                                <a style="margin:5px;" class="btn btn-info btn-sm" rel="tooltip"
                                    href="{php echo createWebUrl('clottery',array('op' => 'recode','id'=>$item['id'],'themeid'=>$themeid));}">
                                    <i class="fa fa-list">中奖名单</i>
                                </a>
                            </td>
                            <td class="text-left" style="line-height: 25px;">
                                <a class="color-default bootstrap-margin-right"
                                    onclick="return confirm('此操作不可恢复，确认删除？');return false;" rel="tooltip"
                                    href="{php echo createWebUrl('clottery',array('op' => 'del','id'=>$item['id'],'themeid'=>$themeid));}">
                                    <i class="fa fa-trash">删除</i>
                                </a><br>
                                <a class="color-default bootstrap-margin-right" rel="tooltip"
                                    href="{php echo createWebUrl('clottery',array('op' => 'enable','status'=>$item['enable'],'id'=>$item['id'],'themeid'=>$themeid));}">
                                    <i class="fa fa-{php echo $item['enable'] == 0 ? 'eye-slash':'eye';}">
                                        {php echo $item['enable'] == 0 ? "禁用" : 启用;}</i>
                                </a><br>
                            </td>
                        </tr>
                        {/loop}
                    </table>

                </div>
                <!--
                <div>
                    <ul class="pagination pagination-centered">
                        {if $targetPage > 0}
                        <li>
                            <a href="{php echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid));}"
                                class="pager-nav">首页</a>
                        </li>

                        <li>
                            <a href="{php echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid,'target'=>$targetPage -1));}"
                                class="pager-nav">&laquo; 上一页</a>
                        </li>
                        {/if}

                        <?php 
                        for ($i=0; $i < $count && $count > 0; $i++) { 
                            echo '<li ';
                            if($i == $targetPage){
                                echo "class='active'";
                            }
                                
                            echo "><a href=\"";
                            echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid,'target'=>$i));
                            echo "\" class=\"pager-nav\">";
                            echo ($i + 1);
                            echo "</a>";
                            echo '</li>';
                        }
                    ?>

                        {if $count > 1}
                        {if $targetPage < $count } <li>
                            <a href="{php echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid,'target' => $targetPage + 1));}"
                                class="pager-nav">下一页&raquo;</a>
                            </li>
                            {/if}
                            <li>
                                <a href="{php echo createWebUrl('clottery',array('op' => 'list','themeid'=>$themeid,'target' => $count));}"
                                    class="pager-nav">尾页</a>
                            </li>
                            {/if}
                    </ul>
                </div>-->
            </div>
        </div>
    </div>
    {/if}
    {if $recode}
    <div class="main">
        <div class="tab-content">
            <div class="tab-pane active" id="basic">
                <div class="panel panel-default" role="tabpanel">
                    <!--<div class="panel-heading" style="display: flex;justify-content: left;align-items: left;">
                        <a style="margin:5px;" class="btn btn-info btn-sm {if empty($gid)} active {/if}" rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','themeid'=>$themeid));}">
                            <i class="fa fa-list">全部</i>
                        </a>
                        <?php
                            $curLottery = null;
                        ?>
                        {loop $result $rv}
                        <?php
                            if($rv['id'] == $gid)
                                $curLottery = $rv;
                        ?>
                        <a style="margin:5px;" class="btn btn-info btn-sm {if $curLottery == $rv} active {/if}"
                            rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','id'=>$rv['id'],'themeid'=>$themeid));}">
                            <i class="fa fa-list">{$rv['name']}</i>
                        </a>
                        {/loop}
                    </div>
                    {if $curLottery}
                    <div class="panel-heading"
                        style="display: flex;justify-content: left;align-items: left;overflow-x: scroll;">
                        <a style="margin:5px;" class="btn btn-info btn-sm {if empty($period)} active {/if}"
                            rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','themeid'=>$themeid,'id'=>$gid));}">
                            <i class="fa fa-list">全部</i>
                        </a>
                        {loop $curLottery['period'] $i $r}
                        <a style="margin:5px;" class="btn btn-info btn-sm {if $r['period'] == $period} active {/if}"
                            rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','id'=>$gid,'period'=>$r['period'],'themeid'=>$themeid));}">
                            <i class="fa fa-list">第{php echo ($i + 1);}期</i>
                        </a>
                        {/loop}
                    </div>
                    {/if}-->
                    <div class="panel-heading" style="display: flex;justify-content: left;align-items: left;overflow-x: scroll;">
                        <a style="margin:5px;" class="btn btn-info btn-sm {if empty($period)} active {/if}"
                            rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','themeid'=>$themeid));}">
                            <i class="fa fa-list">全部</i>
                        </a>
                        {loop $result['period'] $i $r}
                        <a style="margin:5px;" class="btn btn-info btn-sm {if $r == $period} active {/if}"
                            rel="tooltip"
                            href="{php echo createWebUrl('clottery',array('op' => 'recode','period'=>$r,'themeid'=>$themeid));}">
                            <i class="fa fa-list">第{php echo ($i + 1);}期</i>
                        </a>
                        {/loop}
                    </div>
                    <div class="panel-heading">中奖用户</div>
                    <table class="table bootstrap-table table-hover site-list">
                        <tr>
                            <th class="text-left">
                                期
                            </th>
                            <th class="text-left">
                                用户头像
                            </th>
                            <th class="text-left">
                                昵称
                            </th>
                            <th class="text-left">
                                姓名
                            </th>
                            <th class="text-left">
                                手机号码
                            </th>
                            <th class="text-left">
                                奖品
                            </th>
                            <th class="text-left">
                                中奖时间
                            </th>
                        </tr>
                        <!--
                        {loop $result $rv}
                        {loop $rv['period'] $i $r}

                        {loop $r['users'] $u}
                        <tr>
                            <td class="text-left">
                                <img style="width: 40px;height: 40px;border-radius: 50%;"
                                    src="{php echo $u['avatar'];}" />
                            </td>
                            <td class="text-left">
                                {$u['nickname']}
                            </td>
                            <td class="text-left">
                                {$u['username']}{if $u['virtual']} 虚拟用户 {/if}
                            </td>
                            <td class="text-left">
                                {$u['mobile']}{if $u['virtual']} 虚拟用户 {/if}
                            </td>
                            <td class="text-left">
                                {$rv['name']}第{php echo ($i + 1);}期
                            </td>
                            <td class="text-left">
                                {php echo date('Y-m-d H:i',$rv['time']);}
                            </td>
                        </tr>
                        {/loop}
                        {/loop}
                        {/loop}-->
                        {loop $result['recode'] $r}
                            {loop $r['users'] $u}
                            <tr>
                                <td class="text-left">
                                    第{php echo (queryPeriod($r['period'],$result['period']) + 1);}期
                                </td>
                                <td class="text-left">
                                    <img style="width: 40px;height: 40px;border-radius: 50%;"
                                        src="{php echo $u['avatar'];}" />
                                </td>
                                <td class="text-left">
                                    {$u['nickname']}
                                </td>
                                <td class="text-left">
                                    {if $u['virtual']} 虚拟用户 {else} {$u['username']} {/if}
                                </td>
                                <td class="text-left">
                                    {if $u['virtual']} 虚拟用户 {else} {$u['mobile']} {/if}
                                </td>
                                <td class="text-left">
                                    {php echo queryGift($r['id'],$result['gift']);}
                                </td>
                                <td class="text-left">
                                    {php echo date('Y-m-d H:i',$r['time']);}
                                </td>
                            </tr>
                            {/loop}
                        {/loop}
                    </table>
                </div>
            </div>
        </div>
    </div>
    {/if}
    <div class="col-sm-12">
        <a target='_blank' href="{php echo createWebUrl('clotterypage',array('themeid'=>$themeid));}">
            <p class="btn btn-primary col-lg-2">去抽奖</p>
        </a>
        <a  target='_blank' href="{php echo createWebUrl('clottery',array('themeid'=>$themeid,'op'=>'expoler'));}">
            <p style="margin-left: 40px;" class="btn btn-primary col-lg-2">导出抽奖数据</p>
        </a>
    </div>
    